package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import model.Course;
import util.ConnectionUtil;

public class CourseDao {

	public static ArrayList<Course> queryCourseList() {
		ArrayList<Course> courseList = new ArrayList<>();
		
		Connection conn = ConnectionUtil.getConnection();
		String sql = "select * from course";
		try {
			Statement stat = conn.createStatement();
			ResultSet rs = stat.executeQuery(sql);
			
			while(rs.next()) {
				int course_id = rs.getInt(1);
				String course_name = rs.getString(2);
				String course_teacher = rs.getString(3);
				
				Course course = new Course(course_name, course_teacher, course_id);
				courseList.add(course);
			}
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return courseList;
	}

}